#include <iostream>
#include "mgr/ImgWriterMgr.h"
#include "lib_json/json.h"
#include "tool/Utility.h"
#include "tool/Proto.h"
#include "mgr/LogMgr.h"

int ImgWriterMgr::Init(const std::string& conf_file) {
	Json::Value root;
	if (!Utility::LoadJson(conf_file, root)) return -1;
	std::string output = root["output"].asString();
    // TODO 先写死5个
    for (size_t i = 0; i < 5; i++)
    {
        m_writers.push_back(std::make_shared<ImgWriter>(output));
    }
    
	return 0;
}

void ImgWriterMgr::Run() {
    for (size_t i = 0; i < m_writers.size(); i++)
    {
        m_writers[i]->Run();
    }
}

void ImgWriterMgr::Push(const ImgWriteInfo& info){
    int _id = info.id % m_writers.size();
    m_writers[_id]->Push(info);
}